package com.qfedu.java1234.entity.vo;

import com.qfedu.java1234.entity.enums.ResultEnum;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

/**
 * @ClassName ResultVO
 * @Author ykx
 * @Date 2024/1/3 23:38
 * @Version 1.0
 */
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class ResultVO<T> {
    /**
     * 状态码
     */
    private Integer code;

    /**
     * 消息
     */
    private String msg;

    /**
     * 返回数据
     */
    private T data;

    public ResultVO(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public ResultVO(ResultEnum resultEnum) {
        this.code = resultEnum.getCode();
        this.msg = resultEnum.getMsg();
    }

    public static <T> ResultVO success() {
        return new ResultVO(ResultEnum.SUCCESS);
    }


    public static <T> ResultVO success(T data) {
        ResultVO<T> resultVO = new ResultVO<>(ResultEnum.SUCCESS);
        resultVO.setData(data);
        return resultVO;
    }

    public static <T> ResultVO failed() {
        return new ResultVO(ResultEnum.FAILED);
    }

    public static <T> ResultVO failed(Integer code, String msg) {
        return new ResultVO(code, msg);
    }

    public static <T> ResultVO failed(String msg) {
        return new ResultVO(500, msg);
    }

}
